package com.example.exam.ZhangFengHua;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;

import androidx.fragment.app.Fragment;

import com.example.exam.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class Remember_password extends Fragment {
    @BindView(R.id.tv_user)
    EditText tvUser;
    @BindView(R.id.tv_password)
    EditText tvPassword;
    @BindView(R.id.cb_jzpassword)
    CheckBox cbJzpassword;
    @BindView(R.id.bu_land)
    Button buLand;
    private int i;
    private String password;
    private String name;
    public Remember_password() {
    }
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_remember_password, container, false);
        ButterKnife.bind(this, view);
        initview();
        return view;
    }
    private void initview() {
        SharedPreferences zhmm = getContext().getSharedPreferences("zhmm", Context.MODE_PRIVATE);
        if (zhmm!=null){
            name=zhmm.getString("name","");
            password=zhmm.getString("password","");
            i=zhmm.getInt("check",0);
        }
        if (i==1){
            cbJzpassword.setChecked(true);
            tvUser.setText(name);
            tvPassword.setText(password);
        }
    }
    @OnClick(R.id.bu_land)
    public void onViewClicked() {
        SharedPreferences sp = getContext().getSharedPreferences("zhmm", Context.MODE_PRIVATE);
        SharedPreferences.Editor edit = sp.edit();
        edit.putString("name",tvUser.getText().toString());
        edit.putString("password",tvPassword.getText().toString());
        if (cbJzpassword.isChecked()){
            i=1;
            edit.putInt("check",i);
        }else{
            i=0;
            edit.putInt("check",i);
        }
        edit.commit();
        Toast.makeText(getContext(), "登陆成功", Toast.LENGTH_SHORT).show();

    }
}
